package nl.Viewer.ViewManager;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;

/**
 * This is a class for managing the status bar for a view frame 
 * 
 * @author Jeroen Verschuur
 *
 */

public class ViewStatusBar extends JPanel {
   private static final long   serialVersionUID = -9143185441740957999L;
   private JLabel              message;
   private JProgressBar        progressBar      = new JProgressBar();
   private final static String defaultStatus    = " Ready";

   public ViewStatusBar() {
      super( new BorderLayout() );

      create();
   }

   private void create() {
      setPreferredSize( new Dimension( 10, 22 ) );

      message = new JLabel( defaultStatus );
      add( message, BorderLayout.LINE_START );

      JPanel progressPanel = new JPanel( new FlowLayout( FlowLayout.RIGHT, 5, 2 ) );

      progressBar.setStringPainted( true );
      progressPanel.add( progressBar );
      add( progressPanel, BorderLayout.LINE_END );

   }

   public void setDefaultProgress() {
      message.setText( defaultStatus );
      progressBar.setVisible( false );
   }

   public void setProgress( String algorithm, int progress ) {
      if( algorithm.length() == 0 ) {
         //System.out.println( "Algorithm empty" );
         message.setText( "" );
         if( progressBar.isVisible() == true ) {
            progressBar.setVisible( false );
         }
      } else {
         message.setText( " " + algorithm );

         progressBar.setValue( progress );
         if( progressBar.isVisible() == false ) {
            progressBar.setVisible( true );
         }
      }
   }

}
